package com.tiejun.ge.mvc.config;

import com.tiejun.ge.mvc.entity.bo.SystemConfigBO;
import com.tiejun.ge.mvc.service.SystemConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: springboot
 * @description: 项目配置项启动加载
 * @author: getiejun
 * @create: 2025-08-23 21:37
 **/
@Component
@Slf4j
public class ConfigLoader implements CommandLineRunner {

    @Resource
    private SystemConfigService systemConfigService;

    @Resource
    private SystemCatch systemCatch;

    @Override
    public void run(String... args) throws Exception {
        reloadSystemConfig();
    }

    private void reloadSystemConfig(){
        List<SystemConfigBO> configList = systemConfigService.list(new SystemConfigBO());
        configList.forEach(systemConfigBO -> systemCatch.put(systemConfigBO.getItem(), systemConfigBO.getValue()));
    }
}
